﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qiang.Geometry
{
    public class Polygon : Surface, IPolygon
    {

        #region 初始化

        public Polygon()
        { }

        public Polygon(IList<Coordinate> coordinates)
        {
 
        }

        public Polygon(ILinearRing exteriorRing)
            :base()
        {
            _exteriorRing = exteriorRing;
            _holes = new List<ILinearRing>();
        }

        public Polygon(ILinearRing exteriorRing, IList<ILinearRing> holes)
        {
            _exteriorRing = exteriorRing;
            _holes = holes;
        }

        #endregion

        #region 属性

        /// <summary>
        /// 几何类型
        /// </summary>
        public override GeometryType GeometryType
        {
            get { return GeometryType.Polygon; }
        }


        ILinearRing _exteriorRing;

        /// <summary>
        /// 外壳。
        /// </summary>
        public ILinearRing ExteriorRing
        {
            get { return _exteriorRing; }
            set { _exteriorRing = value; }
        }


        IList<ILinearRing> _holes;

        /// <summary>
        /// 洞。
        /// </summary>
        public IList<ILinearRing> Holes
        {
            get { return _holes; }
            set { _holes = value; }
        }

        /// <summary>
        /// 洞数量。
        /// </summary>
        public int NumHoles
        {
            get { return _holes.Count; }
        }


        /// <summary>
        /// 
        /// </summary>
        public override IList<Coordinate> Coordinates
        {
            get
            {
                List<Coordinate> coors = new List<Coordinate>();
                coors.AddRange(ExteriorRing.Coordinates);
                foreach (ILinearRing ring in _holes)
                {
                    coors.AddRange(ring.Coordinates);
                }
                return coors;
            }
            set
            {
                if (value == null || value.Count < 3) return;
                ExteriorRing.Coordinates = value;
            }
        }


        /// <summary>
        /// 是否为空。
        /// </summary>
        public override bool IsEmpty
        {
            get { return ExteriorRing.IsEmpty; }
        }

        #endregion



        #region 方法


       

        #endregion




    }

}
